package com.prs.moa.system.model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;


/**
 * 这是一个树的模型
 * @author prs
 *
 */
@Table(name="SYSTEM_TREE")
@Entity
public class TreeModel implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Id
	@Column(name = "ID_")
	@GenericGenerator(name="uuid",strategy="uuid")
	@GeneratedValue(generator="uuid")
	private String id;
	
	@Column(name = "TREEID_")
	private String treeId;
	
	@Column(name="PARENTID_")
	private String parentId;
	
	@Column(name="STATE_")
	private String state;
	
	@Column(name="TEXT_")
	private String text;
	
	@OneToMany(cascade= CascadeType.ALL)
	@JoinColumn(name="PARENTID_")
	private List<TreeModel> children;
	
	@Transient
	private String iconCls;
	
	@Transient
	private Map<String, Object> attributes;
	
	public Map<String, Object> getAttributes() {
		if(null == this.attributes){
			this.attributes = new HashMap<String, Object>();
		}
		this.attributes.put("treeId", this.treeId);
		return attributes;
	}

	public void setAttributes(Map<String, Object> attributes) {
		this.attributes = attributes;
	}

	public String getIconCls() {
		this.iconCls = "icon-app";
		return iconCls;
	}

	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTreeId() {
		return treeId;
	}

	public void setTreeId(String treeId) {
		this.treeId = treeId;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public List<TreeModel> getChildren() {
		return children;
	}

	public void setChildren(List<TreeModel> children) {
		this.children = children;
	}
}
